var audioTool = {
  // 判断浏览器环境，要求是微信浏览器，并且ios系统是13以上，安卓是7.0.15以上
  checkMobileVersion() {
    let ua = navigator.userAgent;
    let isWx = ua.toLowerCase().match(/MicroMessenger/i) == "micromessenger" && localStorage.getItem('isWxApp') != 1; //判断是微信浏览器 && 不是小程序环境，小程序环境用不了开放标签
    let host = window.location.host;
    let hostAllows = ["kptest.ckjr001.com", "kptest2.ckjr001.com", "formal.ckjr001.com", "wx.ckjryy.com", "sdt.zhiku001.top"];
    const isHost = !!(host.indexOf('.wx.ckjr001.com') > -1 || hostAllows.includes(host));
    if (!(isWx && audioTool.isMobileUserAgent() && isHost) || (sessionStorage.getItem("jsConfigError") && sessionStorage.getItem("jsConfigError") == 1)) {
      return false;
    }
    let isIos = ua.toLowerCase().indexOf("iphone") > -1;
    let WxArr = ua.match(/MicroMessenger\/([\d\.]+)/i);
    let wxVersion = (WxArr && WxArr[1]) || "0.0.0";
    let isAdr = ua.indexOf("Android") > -1 || ua.indexOf("Adr") > -1; //android终端
    let ios13 = "";
    if (isIos) {
      let s = ua
        .toLowerCase()
        .match(/cpu iphone os (.*?) like mac os/)[1]
        .replace(/_/g, ".");
      ios13 = s.toString().split(".")[0] >= 13;
    }
    let adr7 = audioTool.calcVersion(wxVersion, "7.0.15");
    return isAdr ? adr7 : isIos ? adr7 && ios13 : false;
  },
  calcVersion: function (t, e) {
    let i = o(t);
    let a = o(e);
    function o(t) {
      let e = t.toString().split(".");
      let i = ["", "0", "00", "000"];
      i = i.reverse();
      for (let a = 0; a < e.length; a++) {
        let o = e[a].length;
        e[a] = i[o] + e[a];
      }
      var s = e.join("");
      return s;
    }
    return i >= a;
  },
  isMobileUserAgent: () => {
    return /iphone|ipad|ipod|android|android.*mobile|windows.*phone|blackberry.*mobile/i.test(
      window.navigator.userAgent.toLowerCase()
    );
  }
};

export { audioTool };
